import 'package:animal/constant/color.dart';
import 'package:animal/constant/font.dart';
import 'package:animal/item/card_item.dart';
import 'package:animal/ui/goods/Controller/goods_info_controller.dart';
import 'package:animal/utils/screen_util.dart';
import 'package:animal/widgets/button/icon_text_button.dart';
import 'package:animal/widgets/image_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_plus/flutter_swiper_plus.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';

///商品详情
class GoodsInfoPage extends StatelessWidget {
  GoodsInfoPage({Key? key}) : super(key: key);
  late GoodsInfoController controller;

  @override
  Widget build(BuildContext context) {
    controller = Get.put(GoodsInfoController());
    return Scaffold(
        backgroundColor: KColorConstant.appBgColor,
        body: NestedScrollView(
            headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
              return <Widget>[
                SliverOverlapAbsorber(
                  handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                  sliver: Obx(() => _buildSliverAppBar()),
                )
              ];
            },
            body: Stack(
              alignment: Alignment.bottomCenter,
              children: [
                SingleChildScrollView(
                  controller: controller.scrollController,
                  child: Column(
                    children: [
                      Container(
                          height: ScreenUtil().L(300),
                          child: Swiper(
                            loop: true,
                            autoplay: true,
                            itemHeight: ScreenUtil().L(150),
                            itemBuilder: (BuildContext context, int index) {
                              return ImageWidget(
                                borderRadius: BorderRadius.circular(0),
                              );
                            },
                            itemCount: 3,
                            pagination: const SwiperPagination(),
                            control: const SwiperControl(size: 0),
                          )),
                      Container(
                        width: double.infinity,
                        padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(15), vertical: ScreenUtil().L(15)),
                        color: Colors.white,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("韩国cokoeye美瞳半年抛盒女小直径隐形近视眼镜彩色正品大牌",
                                style: KFontConstant.myTextStyle(
                                  size: 16,
                                  height: 1.5,
                                )),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Text("￥899 - 4999", style: KFontConstant.myTextStyle(size: 18, color: Colors.red)),
                                Obx(() {
                                  return IconTextButton(
                                    name: "收藏",
                                    widgetWidth: ScreenUtil().L(30),
                                    widgetHeight: ScreenUtil().L(40),
                                    iconWidget: Image.asset("images/${controller.isCheck.value ? "collection" : "collection_null"}.png"),
                                    direction: Direction.bottom,
                                    padding: ScreenUtil().L(5),
                                    style: KFontConstant.myTextStyle(size: 13, color: KColorConstant.black666666),
                                    onTap: () => controller.isCheck.value = !controller.isCheck.value,
                                  );
                                })
                              ],
                            )
                          ],
                        ),
                      ),
                      Container(
                        color: Colors.white,
                        margin: EdgeInsets.only(top: ScreenUtil().L(15)),
                        padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(15)),
                        child: Column(
                          children: [
                            Container(
                              padding: EdgeInsets.symmetric(vertical: ScreenUtil().L(17)),
                              color: Colors.white,
                              child: Row(
                                children: [
                                  Text(
                                    "规格",
                                    style: KFontConstant.myTextStyle(size: 14, color: KColorConstant.grayA9A9A9),
                                  ),
                                  Container(width: ScreenUtil().L(20)),
                                  InkWell(
                                    child: Text("请选择", style: KFontConstant.myTextStyle(size: 14)),
                                    onTap: () => controller.selectNorms(),
                                  ),
                                ],
                              ),
                            ),
                            Divider(
                              height: ScreenUtil().L(2),
                              endIndent: ScreenUtil().L(30),
                            ),
                            Container(
                              margin: EdgeInsets.only(top: ScreenUtil().L(2)),
                              padding: EdgeInsets.symmetric(vertical: ScreenUtil().L(17)),
                              color: Colors.white,
                              child: Row(
                                children: [
                                  Text(
                                    "运费",
                                    style: KFontConstant.myTextStyle(size: 15, color: Colors.black38),
                                  ),
                                  Container(width: ScreenUtil().L(20)),
                                  Text("56元", style: KFontConstant.myTextStyle(size: 16)),
                                  Container(
                                    width: ScreenUtil().L(40),
                                    height: ScreenUtil().L(20),
                                    margin: EdgeInsets.only(right: ScreenUtil().L(10)),
                                    decoration: BoxDecoration(border: Border(right: BorderSide(width: ScreenUtil().L(1), color: Colors.black38))),
                                  ),
                                  Expanded(
                                      child: Text("发货地：内蒙古 呼和浩特市 新城区..",
                                          style: KFontConstant.myTextStyle(size: 16, color: KColorConstant.black666666), overflow: TextOverflow.ellipsis)),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().L(2)),
                        padding: EdgeInsets.symmetric(vertical: ScreenUtil().L(10), horizontal: ScreenUtil().L(15)),
                        color: Colors.white,
                        child: Row(
                          children: [
                            ImageWidget(width: 70, height: 70, borderRadius: BorderRadius.circular(0)),
                            Container(width: ScreenUtil().L(10)),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text("韩国重庆专卖店", style: KFontConstant.myTextStyle(size: 16)),
                                  Container(height: ScreenUtil().L(20)),
                                  Container(
                                    margin: EdgeInsets.only(left: ScreenUtil().L(15)),
                                    child: Row(
                                      children: [
                                        CardItem(
                                            text: "实名认证", imageWidth: ScreenUtil().l(20), textStyle: KFontConstant.myTextStyle(size: 13, color: Colors.blue)),
                                        Container(width: ScreenUtil().L(20)),
                                        CardItem(
                                            text: "商家认证", imageWidth: ScreenUtil().l(20), textStyle: KFontConstant.myTextStyle(size: 13, color: Colors.blue)),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                            ),
                            GFButton(
                                text: "进入店铺",
                                textStyle: KFontConstant.myTextStyle(size: 17, color: Colors.blue),
                                onPressed: () => controller.gotoShopInfo(),
                                type: GFButtonType.outline)
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().L(15), bottom: ScreenUtil().L(10)),
                        padding: EdgeInsets.only(top: ScreenUtil().L(30), bottom: ScreenUtil().L(15)),
                        color: Colors.white,
                        child: Column(
                          children: [
                            Text("商品详情", style: KFontConstant.myTextStyle(size: 20, color: Colors.black)),
                            Divider(
                                height: ScreenUtil().L(20),
                                color: Colors.blue,
                                thickness: ScreenUtil().L(1.5),
                                indent: ScreenUtil().L(120),
                                endIndent: ScreenUtil().L(120))
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().L(15), bottom: ScreenUtil().L(10)),
                        padding: EdgeInsets.only(top: ScreenUtil().L(30), bottom: ScreenUtil().L(15)),
                        color: Colors.white,
                        child: Column(
                          children: [
                            Text("价格说明", style: KFontConstant.myTextStyle(size: 20, color: Colors.blue)),
                            Divider(
                                height: ScreenUtil().L(20),
                                color: Colors.blue,
                                thickness: ScreenUtil().L(1.5),
                                indent: ScreenUtil().L(120),
                                endIndent: ScreenUtil().L(120)),
                            Text("""
•划线价格
指商品的专柜价、吊牌价、正品零售价、厂商指导价或该商品的曾经展示过的销售价等，并非原价，仅供参考。
• 未划线价格
指商品的实时标价，不因表述的差异改变性质。具体成交价格根据商品参加活动，或会员使用优惠券、积分等发生变化，最终以订单结算页价格为准。
若商家单独对划线价格进行说明的，以商家的表述为准。""", style: KFontConstant.myTextStyle(size: 15, color: Colors.black38))
                          ],
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: ScreenUtil().L(15), bottom: ScreenUtil().L(10)),
                        padding: EdgeInsets.only(top: ScreenUtil().L(30), bottom: ScreenUtil().L(15)),
                        child: Column(
                          children: [
                            Text("商品推荐", style: KFontConstant.myTextStyle(size: 20, color: Colors.blue)),
                            Divider(
                                height: ScreenUtil().L(20),
                                color: Colors.blue,
                                thickness: ScreenUtil().L(1.5),
                                indent: ScreenUtil().L(120),
                                endIndent: ScreenUtil().L(120)),
                            GridView.builder(
                                shrinkWrap: true,
                                padding: EdgeInsets.only(bottom: ScreenUtil().L(40)),
                                itemCount: 6,
                                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                                    crossAxisCount: 2, crossAxisSpacing: ScreenUtil().L(10), mainAxisSpacing: ScreenUtil().L(10), childAspectRatio: 1.0),
                                itemBuilder: (context, index) {
                                  return Container(
                                    color: Colors.blue,
                                  );
                                })
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
                Container(
                  padding: EdgeInsets.fromLTRB(
                    ScreenUtil().L(15),
                    ScreenUtil().L(10),
                    ScreenUtil().L(15),
                    ScreenUtil().L(5),
                  ),
                  decoration: BoxDecoration(color: Colors.white, boxShadow: [
                    BoxShadow(
                      color: Colors.black12,
                      offset: Offset(0, ScreenUtil().L(15)),
                      blurRadius: ScreenUtil().L(1),
                      spreadRadius: ScreenUtil().l(18),
                    )
                  ]),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      IconTextButton(
                        name: "店铺",
                        direction: Direction.bottom,
                        iconWidget: Image.asset("images/shop.png"),
                        style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.black222),
                        widgetHeight: ScreenUtil().L(50),
                        widgetWidth: ScreenUtil().L(40),
                      ),
                      IconTextButton(
                        name: "聊一聊",
                        direction: Direction.bottom,
                        style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.black222),
                        iconWidget: Image.asset("images/customer.png"),
                        widgetWidth: ScreenUtil().L(40),
                        widgetHeight: ScreenUtil().L(50),
                      ),
                      IconTextButton(
                        name: "购物车",
                        direction: Direction.bottom,
                        style: KFontConstant.myTextStyle(size: 12, color: KColorConstant.black222),
                        iconWidget: const Icon(Icons.shopping_cart_outlined),
                        widgetWidth: ScreenUtil().L(40),
                        widgetHeight: ScreenUtil().L(50),
                      ),
                      Row(
                        children: [
                          CupertinoButton(
                              color: const Color(0XFFFF605F),
                              padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(20)),
                              borderRadius: BorderRadius.horizontal(left: Radius.circular(ScreenUtil().L(20)), right: Radius.circular(ScreenUtil().L(0))),
                              child: Text(
                                "加入购物车",
                                style: KFontConstant.myTextStyle(size: 14, color: Colors.white),
                              ),
                              onPressed: () => Container()),
                          CupertinoButton(
                              color: const Color(0XFFFFA940),
                              padding: EdgeInsets.symmetric(horizontal: ScreenUtil().L(25)),
                              borderRadius: BorderRadius.horizontal(right: Radius.circular(ScreenUtil().L(20)), left: Radius.circular(ScreenUtil().L(0))),
                              child: Text(
                                "立即购买",
                                style: KFontConstant.myTextStyle(size: 14, color: Colors.white),
                              ),
                              onPressed: () => Container()),
                        ],
                      ),
                    ],
                  ),
                )
              ],
            )));
  }

  ///上部分AppBar内容
  Widget _buildSliverAppBar() {
    return SliverAppBar(
      pinned: true,
      backgroundColor: controller.appBarColor.value,
      leading: GFIconButton(
        icon: Image.asset(
          "icons/icon_back.png",
          color: Colors.white,
          width: ScreenUtil().L(20),
        ),
        onPressed: () => Get.back(),
        padding: const EdgeInsets.all(0),
        size: ScreenUtil().L(15),
        color: Colors.black26,
        shape: GFIconButtonShape.circle,
        type: GFButtonType.transparent,
      ),
      centerTitle: true,
      title: Text("商品详情",
          style:
              KFontConstant.myTextStyle(size: 17, bold: true, color: controller.appBarColor.value == Colors.transparent ? Colors.transparent : Colors.white)),
      actions: [
        Container(
          margin: EdgeInsets.only(right: ScreenUtil().L(10)),
          child: GFIconButton(
            shape: GFIconButtonShape.circle,
            type: GFButtonType.transparent,
            size: GFSize.SMALL,
            onPressed: () {},
            icon: const Icon(Icons.share, color: Colors.white),
          ),
        ),
      ],
      elevation: 1,
    );
  }
}
